﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace web
{
    public class CheckData
    {
        public string ActionName { get; set; }
        public string ControllerName { get; set; }
        /// <summary>
        /// 返回类型
        /// 如果通过则用回原来的控制器或动作，不通过则用权限或不存在的控制器和动作返回
        /// 1 通过
        /// 2 请求的东西不存在
        /// 3 请求的东西需要权限
        /// </summary>
        public int ResultType { get; set; }
    }
    public class BaseRule : System.Web.Mvc.AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            object loginUser = httpContext.Session["login_user"];
            if (null != loginUser)
            {
                return true;
            }
            return false;
        }

        public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
        {
            if (AuthorizeCore(filterContext.HttpContext) != true)
            {
                filterContext.HttpContext.Response.StatusCode = 302;
                filterContext.Result = new RedirectResult("~/Auth/Login");
            }
        }
    }
}